package com.xtaifghy.wugui.ui;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ButtonPanel extends JPanel {
    GamePanel gamePanel;
    public ButtonPanel(GamePanel gamePanel) {
        super();
        this.gamePanel = gamePanel;
        init();
    }
    public void init(){
        setLayout(new GridLayout(3,3));
        ActionListener btnAction=new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                String txt=((JButton)e.getSource()).getText();
                gamePanel.doAction(Integer.valueOf(txt));
            }
        };
        for(int i=0;i<9;i++){
            JButton jButton = new JButton(""+i);
            jButton.addActionListener(btnAction);
            add(jButton);
        }
    }
}
